package com.zynn.service.module.canal.service.impl;

import com.zynn.common.core.utils.TypeConvertUtil;
import com.zynn.feign.module.es.SyncEventFeignService;
import com.zynn.message.queue.constant.MqQueueNameConstant;
import com.zynn.message.queue.service.ScheduleMessagePostProcessor;
import com.zynn.message.queue.service.SenderService;
import com.zynn.service.module.canal.service.RemindUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.Objects;

/**
 *@ClassName RemindUserServiceImpl
 *@Description TODO
 *@Author 刘猛
 *@Date 2018/10/9 16:19
 **/

@Service
@Slf4j
public class RemindUserServiceImpl implements RemindUserService {

    @Autowired
    SyncEventFeignService syncEventFeignService;

    @Autowired
    private SenderService senderService;

    @Override
    public void handleInsert(Map<String, Object> columnsMap) {
        senderService.send(MqQueueNameConstant.FIND_FRIEND_REMINDUSER, columnsMap,new ScheduleMessagePostProcessor(1000L,0L,null,null));
    }

    @JmsListener(destination = MqQueueNameConstant.FIND_FRIEND_REMINDUSER)
    public void findDegOneFriend(Map<String, Object> columnsMap) {
        log.info("FIND_FRIEND_REMINDUSER:{}", columnsMap);
        /**
         * 主动@的用户id
         */
        Long userId = TypeConvertUtil.objectToLong(columnsMap.get("userId"));
        if(Objects.nonNull(userId)){
            syncEventFeignService.initProcuctFriend(userId);
        }

        /**
         * 被@的用户id
         */
        Long remindUserId = TypeConvertUtil.objectToLong(columnsMap.get("remindUserId"));
        if(Objects.nonNull(remindUserId)){
            syncEventFeignService.initProcuctFriend(remindUserId);
        }

    }


}
